package com.mingtu.jgspatrol.adapter;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.center.bean.MyTrackBean;
import com.mingtu.common.utils.MyUtills;
import com.mingtu.jgspatrol.R;

public class MyRecordTrackAdapter extends BaseQuickAdapter<MyTrackBean.PageBean.ListBean, BaseViewHolder> {

    public MyRecordTrackAdapter() {
        super(R.layout.item_my_track_record);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, MyTrackBean.PageBean.ListBean listBean) {
        String taskName = listBean.getTaskName();
        String duration = listBean.getDuration();
        String mileage = listBean.getMileage();
        String beginTime = listBean.getBeginTime();
        String endTime = listBean.getEndTime();
        boolean isUpload = listBean.getIsUpload(); //数据是否上传,false 为未上传的  null 是已上传的
        TextView tvStatus = helper.getView(R.id.tv_status);
        TextView tvNetWorkFlag = helper.getView(R.id.tv_netwoek_flag);
        if (isUpload) {
            tvNetWorkFlag.setVisibility(View.GONE);
            tvStatus.setSelected(true);
            tvStatus.setText("已上传");
            tvStatus.setVisibility(View.GONE);
        } else {

            tvNetWorkFlag.setVisibility(View.VISIBLE);
            tvStatus.setSelected(false);
            tvStatus.setText("未上传");
            tvStatus.setVisibility(View.VISIBLE);

        }

        if (!StringUtils.isEmpty(taskName)) {
            helper.setText(R.id.tv_task_name, "编号：" + taskName);
        }
        if (!StringUtils.isEmpty(duration)) {

            long d = 0;
            if (duration.indexOf(".") != -1) {
                String array[] = duration.split("\\.");
                d = Long.parseLong(array[0]);
            } else {
                d = Long.parseLong(duration);
            }

            helper.setText(R.id.tv_duration, MyUtills.formatSeconds5(d));
        }

        if (!StringUtils.isEmpty(mileage)) {
            helper.setText(R.id.tv_mileage, mileage + "km");
        }
        if (!StringUtils.isEmpty(beginTime)) {
            helper.setText(R.id.tv_begin_time, beginTime);
        }
        if (!StringUtils.isEmpty(endTime)) {
            helper.setText(R.id.tv_end_time, endTime);
        }

    }
}
